package com.lyz.apidemo;

/**
 * @ClassName Test2
 * @Description StringBuilder 拼接字符串
 * @Author 2214361854
 * @Date 2022/2/19 19:18
 * @Version 1.0
 */
public class Test2 {
    public static void main(String[] args) {
        int[] arr = {11,22,33,44,55};
        String s = toString(arr);
        System.out.println(s);
    }
    public static String toString(int[] arr){
        if (arr!=null) {
            StringBuilder sbr = new StringBuilder("[");
            for (int i = 0; i < arr.length; i++) {
                //链式编程
                sbr.append(arr[i]).append(i==arr.length-1?"":",");
            }
            sbr.append("]");
            return sbr.toString();
        }else {
            return null;
        }
    }
}
